package yuan.deng.dao.impl;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import yuan.deng.dao.ItemsDao;
import yuan.deng.domain.Items;
import yuan.deng.utils.DataSourceUtils;

import java.util.List;

public class ItemsDaoImpl implements ItemsDao {
    JdbcTemplate jdbcTemplate =new JdbcTemplate(DataSourceUtils.getDataSource());
    @Override
    public int addItems(Items items) {
        int i = jdbcTemplate.update("insert into items values (?,?,?,?)", items.getId(), items.getIname(), items.getPrice(), items.getAddress());
        return i;
    }

    @Override
    public List<Items> findAll() {
        List<Items> list=null;
        try{
            list = jdbcTemplate.query("select * from items", new BeanPropertyRowMapper<>(Items.class));
            return list;
        }catch (Exception e){
            return null;
        }

    }
}
